home *** CD-ROM | disk | FTP | other *** search
- #include <ad709/tinygl/igl.h>
- #include "zgl.h"
-
- typedef struct {
- GLContext *gl_context;
- int xsize,ysize;
- ave_win_t *drawable;
- ave_pix_t *gc;
- int draw;
- } TinyIGLContext;
-
-
-
- ///////////////// Private aux functions
-
- static int igl_resize_viewport(GLContext *c,int *xsize_ptr,int *ysize_ptr);
- static int igl_init(IGLContext ctx1, int xsize, int ysize);
-
-
- static int igl_init(IGLContext ctx1, int xsize, int ysize) {
- TinyIGLContext *ctx = (TinyIGLContext *) ctx1;
- int mode;
- ZBuffer *zb;
-
- if (ctx->gl_context == NULL) {
- /* currently, we only support 16 bit rendering */
- mode = ZB_MODE_5R6G5B;
- zb=ZB_open(xsize,ysize,mode,0,NULL,NULL,NULL);
- if (zb == NULL) {
- fprintf(stderr, "Error while initializing Z buffer\n");
- exit(1);
- }
- /* initialisation of the TinyGL interpreter */
- glInit(zb);
- ctx->gl_context=gl_get_context();
- ctx->gl_context->opaque=(void *) ctx;
- ctx->gl_context->gl_resize_viewport=igl_resize_viewport;
-
- /* set the viewport : we force a call to glX_resize_viewport */
- ctx->gl_context->viewport.xsize=-1;
- ctx->gl_context->viewport.ysize=-1;
- //glViewport(0, 0, xsize, ysize);
- }
-
- return 1;
- }
-
-
-
- /* resize the glx viewport : we try to use the xsize and ysize
- given. We return the effective size which is guaranted to be smaller */
-
- static int igl_resize_viewport(GLContext *c,int *xsize_ptr,int *ysize_ptr) {
- TinyIGLContext *ctx;
- int xsize,ysize;
-
- ctx=(TinyIGLContext *)c->opaque;
-
- xsize=*xsize_ptr;
- ysize=*ysize_ptr;
-
- /* we ensure that xsize and ysize are multiples of 2 for the zbuffer.
- TODO: find a better solution */
- xsize&=~3;
- ysize&=~3;
-
- if (xsize == 0 || ysize == 0) return -1;
-
- *xsize_ptr=xsize;
- *ysize_ptr=ysize;
-
- ctx->xsize=xsize;
- ctx->ysize=ysize;
-
- /* resize the Z buffer */
- ZB_resize(c->zb,NULL,xsize,ysize);
- return 0;
- }
-
-
-
- ////////////////////////// igl API functions
-
-
- IGLContext iglCreateContext() {
- TinyIGLContext *ctx;
-
- ctx=malloc(sizeof(TinyIGLContext));
- if (!ctx)
- return NULL;
- ctx->gl_context = NULL;
- igl_init(ctx, 0, 0);
- return (IGLContext) ctx;
- }
-
-
- void iglDestroyContext( IGLContext ctx1 ) {
- TinyIGLContext *ctx = (TinyIGLContext *) ctx1;
- if (ctx->gl_context != NULL) {
- glClose();
- }
- free(ctx);
- }
-
-
-
- void iglMakeCurrent(ave_win_t *drawable, IGLContext ctx1) {
- TinyIGLContext *ctx = (TinyIGLContext *) ctx1;
- ave_dialog_gadgets_t win_gadgets;
- ave_avo_size_t win_size;
- int xsize, ysize;
-
- win_size = ave_avo_getsize((ave_avo_t *) drawable);
- xsize = win_size.width;
- ysize = win_size.height;
- igl_resize_viewport(ctx->gl_context, &xsize, &ysize);
- ctx->gc = ave_pix_16bit_open(ctx->gl_context->zb->pbuf, xsize, ysize, xsize*2);
- win_gadgets = ave_dialog_getgadgets(drawable);
- ave_avo_add(win_gadgets.content, (ave_avo_t *) ctx->gc, 0);
- ctx->gl_context->viewport.xsize=-1;
- ctx->gl_context->viewport.ysize=-1;
- }
-
-
-
- void iglResizeContext(IGLContext ctx1, int width, int height, ave_win_t *drawable) {
- ave_dialog_gadgets_t win_gadgets;
- TinyIGLContext *ctx = (TinyIGLContext *) ctx1;
- win_gadgets = ave_dialog_getgadgets(drawable);
- ave_obj_deref((ave_obj_t *) ctx->gc);
- ave_avo_sub(win_gadgets.content, (ave_avo_t *) ctx->gc);
- ctx->gc = ave_pix_16bit_open(ctx->gl_context->zb->pbuf, width, height, width*2);
- ave_avo_add(win_gadgets.content, (ave_avo_t *) ctx->gc, 0);
- }
-
-
- ave_pix_t *iglGetPixmap(IGLContext ctx1) {
- TinyIGLContext *ctx = (TinyIGLContext *) ctx1;
- return ctx->gc;
- }
-
-